package com.sigmazero13.MKDummy.components;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.sigmazero13.MKDummy.R;
import com.sigmazero13.MKDummy.models.CardDeck;
import com.sigmazero13.MKDummy.models.ManaColor;

public class CardDisplayTextCountView extends CardDisplayView {
	
	private TextView redCards;
	private TextView blueCards;
	private TextView greenCards;
	private TextView whiteCards;
	private TextView woundCards;

	
	public CardDisplayTextCountView(Context c) {
		super(c);
		
		commonSetup(c);
	}
	
	public CardDisplayTextCountView(Context c, AttributeSet attrs) {
		super(c, attrs);
		
		commonSetup(c);
	}
	
	
	@Override
	public void onDeckChanged(CardDeck deck) {
		String redText = deck.countCardsRemainingOfColor(ManaColor.RED).toString() + (deck.hasSpellOfColor(ManaColor.RED)?"*":"");
		String blueText = deck.countCardsRemainingOfColor(ManaColor.BLUE).toString() + (deck.hasSpellOfColor(ManaColor.BLUE)?"*":"");
		String greenText = deck.countCardsRemainingOfColor(ManaColor.GREEN).toString() + (deck.hasSpellOfColor(ManaColor.GREEN)?"*":"");
		String whiteText = deck.countCardsRemainingOfColor(ManaColor.WHITE).toString() + (deck.hasSpellOfColor(ManaColor.WHITE)?"*":"");
		String woundText = deck.countCardsRemainingOfColor(ManaColor.WOUND).toString();
		
		redCards.setText(redText);
		blueCards.setText(blueText);
		greenCards.setText(greenText);
		whiteCards.setText(whiteText);
		woundCards.setText(woundText);		
	}
	
	
	@Override
	public void showWounds(Boolean show) {
		if (show) {
			woundCards.setVisibility(View.VISIBLE);
		} else {
			woundCards.setVisibility(View.GONE);
		}
	}
	
	
	private void commonSetup(Context c) {
		LayoutInflater inflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View main = inflater.inflate(R.layout.player_data_count_by_color, this, true);
		
		redCards = (TextView)main.findViewById(R.id.count_red);
		blueCards = (TextView)main.findViewById(R.id.count_blue);
		greenCards = (TextView)main.findViewById(R.id.count_green);
		whiteCards = (TextView)main.findViewById(R.id.count_white);
		woundCards = (TextView)main.findViewById(R.id.count_wound);
	}

}
